package com.demo2do.fms.admin.web.controller.authority.infrastructure;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.entity.page.Page;
import com.demo2do.core.web.interceptor.MenuSetting;
import com.demo2do.fms.admin.service.DataService;
import com.demo2do.fms.entity.authority.Branch;

/**
 * 分区
 * 
 * @author Wy
 *
 */
@Controller
@RequestMapping("/branches")
@MenuSetting("menu-authority")
public class BranchController {
    
    @Autowired
    @Qualifier("dataService")
    private DataService<Branch> branchService;
    
    /**
     * list all
     * 
     * @param page
     * @return
     */
    @RequestMapping(value = "" , method = RequestMethod.GET)
    @MenuSetting("submenu-partition-management")
    public ModelAndView list(Page page){
        
        ModelAndView modelAndView = new ModelAndView("authority/infrastructure/branch/branch-list");
        
        int totals = branchService.count(Branch.class);
        if(totals > 0){
            
            List<Branch> branches = branchService.listByPage(Branch.class, page.with(totals));
            
            modelAndView.addObject("branches", branches);
            modelAndView.addObject("page", page);
        }
        
        return modelAndView;
        
    }
    
}
